package com.stations.controller;

import com.github.pagehelper.PageInfo;
import com.stations.common.aop.annotation.Log;
import com.stations.common.aop.enums.BusinessType;
import com.stations.common.constant.ControllerConstant;
import com.stations.common.web.base.BaseController;
import com.stations.common.web.domain.request.PageDomain;
import com.stations.common.web.domain.response.Result;
import com.stations.common.web.domain.response.module.ResultTable;
import com.stations.domain.TStation;
import com.stations.domain.TTransmitter;
import com.stations.domain.dtree.DTree;
import com.stations.domain.dtree.DTreeResponse;
import com.stations.domain.dtree.Status;
import com.stations.service.StationService;
import com.stations.service.TrasmiterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Describe: 台站控制器
 * Author: Ljy
 * CreateTime: 2019/10/23
 */
@RestController
@Api(tags = {"台站管理"})
@RequestMapping(ControllerConstant.API_SYSTEM_PREFIX + "station")
public class StationsController extends BaseController {

    /**
     * Describe: 基础路径
     */
    private static String MODULE_PATH = "system/station/";

    @Resource
    private StationService stationService;


    /**
     * Describe: 获取台站列表视图
     * Param ModelAndView
     * Return 发射机视图
     */
    @GetMapping(value = "/getAllStation")
    @ApiOperation(value = "获取台站列表")
    @PreAuthorize("hasPermission('/system/station/getAllStation','sys:station:getAllStation')")
    public Result getAllStation() {
        List<TStation> stationList = stationService.selectAll();
        return Result.success(stationList);
    }

    /**
     * 分页查询台站列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/system/station/data','sys:station:data')")
    public ResultTable list(@ModelAttribute TStation tStation, PageDomain pageDomain) {
        PageInfo<TStation> pageInfo = stationService.selectTStationPage(tStation, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * Describe: 发射机添加
     * Param ModelAndView
     * Return 添加结果
     */
    @PostMapping("addStation")
    @ApiOperation(value = "添加台站")
    @PreAuthorize("hasPermission('/system/station/addStation','sys:station:addStation')")
    @Log(title = "添加台站", describe = "添加台站", type = BusinessType.ADD)
    public Result addStation(@RequestBody TStation station) {
        return stationService.add(station);
    }

    /**
     * Describe: 编辑台站
     * Param ModelAndView
     * Return 修改结果
     */
    @PostMapping("editStation")
    @ApiOperation(value = "修改台站信息")
    @PreAuthorize("hasPermission('/system/station/editStation','sys:station:editStation')")
    @Log(title = "修改台站", describe = "修改台站", type = BusinessType.EDIT)
    public Result editStation(@RequestBody TStation station) {
        return stationService.edit(station);
    }

    /**
     * Describe: 删除台站
     * Param ModelAndView
     * Return 修改结果
     */
    @PostMapping("delStation")
    @ApiOperation(value = "删除台站")
    @PreAuthorize("hasPermission('/system/station/delStation','sys:station:delStation')")
    @Log(title = "删除台站", describe = "删除台站", type = BusinessType.REMOVE)
    public Result delStation(@RequestBody TStation station) {
        return stationService.del(station);
    }

    @GetMapping(value = "/getAllIRegion")
    @ApiOperation(value = "获取区域树")
    @PreAuthorize("hasPermission('/system/station/getAllIRegion','sys:station:getAllIRegions')")
    @Log(title = "获取区域树", describe = "获取区域树", type = BusinessType.QUERY)
    public DTreeResponse getAllIRegion(HttpServletRequest request) {
        List<DTree> RegionList = stationService.getTree();
        DTreeResponse response=new DTreeResponse();
        response.setData(RegionList);
        response.setStatus(new Status());
        return response;
    }
}
